import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import { createRootContainer, getRoot, registerRootProviders, inject } from 'what-di';
import { BaseProvider } from 'what-di/lib/base-provider';
import DefaultContainer from "./DefaultContainer";
import * as defaultConfig from "../config";
import { UedProvider } from "./UedProvider";
export var ConfigProvider = /*#__PURE__*/function (_BaseProvider) {
  _inherits(ConfigProvider, _BaseProvider);

  var _super = _createSuper(ConfigProvider);

  function ConfigProvider() {
    var _this;

    _classCallCheck(this, ConfigProvider);

    _this = _super.call(this);
    _this._config = void 0;
    _this._config = _objectSpread({}, defaultConfig);
    return _this;
  }

  _createClass(ConfigProvider, [{
    key: "extends",
    value: function _extends(config) {
      this._config = _objectSpread(_objectSpread({}, this.config), config);
    }
  }, {
    key: "config",
    get: function get() {
      return this._config;
    }
  }]);

  return ConfigProvider;
}(BaseProvider);
var configProvider = {
  provide: 'config',
  useClass: ConfigProvider
};
export function initIoc() {
  var root = getRoot();

  if (!root) {
    createRootContainer({
      providers: []
    });
  } // 初始化环境变量


  var conf = inject('config');

  if (!conf) {
    registerRootProviders([configProvider]);
  } // 初始化UED


  var ued = inject(UedProvider);

  if (!ued) {
    // @ts-ignore
    registerRootProviders([UedProvider]);
    var u = inject(UedProvider);
    u.registerContainer(DefaultContainer);
  }
}